<template>
  <div class="distribute">
    <DFPageList ref="dfPageListRef" :pageOptions="pageOptions" />
  </div>
</template>

<script lang="ts" setup name="GatherMachine">
  import lang from './lang';
  import { useMixins } from '@/hooks/useMixins';
  import { pageDistribute, delDistribute } from '@/api/gather/distribute';
  import { listMachine } from '@/api/base/machine';

  const { loadLangFn } = useMixins();
  loadLangFn(lang);

  const dfPageListRef: any = ref(null);

  const machineList = ref([]);

  const pageOptions = {
    searchForm: {
      formSchemas: [
        {
          label: 'machineName',
          prop:'machineCode',
          component: 'NSelect',
          options: machineList,
        },
      ],
    },
    table: {
      columns: [
        {
          width: 170,
          label: 'machineName',
          render:(row)=>{
            return h('span',{
              innerText:row.machineCode?machineList.value.find(item=>item.value===row.machineCode).label:'-'
            })
          }
        },
        {
          width: 170,
          label: 'machineCode',
        },
        {
          width: 170,
          label: 'remark',
          common:true
        },
      ],
      action: {
        columns: [
          {
            label: 'edit',
            hump: true,
          },
          {
            label: 'copy',
            hump: true,
          },
          {
            label: 'delete',
          },
        ],
      },
      operaColumn: [
        {
          label: 'add',
          hump: true,
        },
      ],
      requestFn: pageDistribute,
      delRequestFn: delDistribute,
    },
  };

  const initDictData = async() => {
    const res = await Promise.all([listMachine()]);

    const [list1] = res;

    machineList.value = list1?.data.map(item => ({ label: item.machineName, value: item.machineCode })) || [];
  };

  initDictData()
</script>
